package com.app.mobileshopapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.mobileshopapp.entity.Product;

public class ProductActivity extends AppCompatActivity {
    Product product;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product);
        initData();
        initView();
    }

    private void initView() {

        ImageView ivProductPic =findViewById(R.id.iv_product_pic);

        TextView tvProductName =findViewById(R.id.tv_product_name);
        TextView tvProductDesc = findViewById(R.id.tv_product_description);
        TextView tvProductPrice = findViewById(R.id.tv_product_price);


        ivProductPic.setImageResource(getImageIdentify(product));
        tvProductName.setText(product.getProductName());
        tvProductDesc.setText(product.getDescription());
        tvProductPrice.setText("价格:"+product.getPrice()+"元");
    }

    private void initData() {
        Intent intent = getIntent();
        product = (Product) intent.getSerializableExtra("product");
    }
    private int getImageIdentify(Product product) {
        int identifier = getResources()
                .getIdentifier(product.getProductPic().split("\\.")[0]
                        , "mipmap", getPackageName());
        return identifier;
    }
}
